
package com.epam.android.training.day3.task1;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

/**
 * Application activity which notify about changes in its lifecycle.
 * 
 * @author Anton Novikau
 */
public class LifecycleActivityCheck extends Activity {
    private static final String LOGGER_TAG = LifecycleActivityCheck.class.getSimpleName();

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Log.i(LOGGER_TAG, "Activity created.");
        showToastMessage(R.string.on_create_message);
    }

    /**
     * Called after {@link #onStop()} when the current activity is being
     * re-displayed to the user.
     */
    @Override
    protected void onRestart() {
        super.onRestart();
        Log.i(LOGGER_TAG, "Activity restarted.");
        showToastMessage(R.string.on_restart_message);
    }

    /**
     * Called after {@link #onRestoreInstanceState(Bundle)},
     * {@link #onRestart()}, or {@link #onPause()}, for activity to start
     * interacting with the user.
     */
    @Override
    protected void onResume() {
        super.onResume();

        Log.i(LOGGER_TAG, "Activity resumed.");
        showToastMessage(R.string.on_resume_message);
    }

    /**
     * Called when activity is no longer visible to the user.
     */
    @Override
    protected void onStop() {
        super.onStop();

        Log.i(LOGGER_TAG, "Activity stopped.");
        showToastMessage(R.string.on_stop_message);
    }

    private void showToastMessage(int messageResource) {
        Toast.makeText(getApplicationContext(), messageResource, Toast.LENGTH_SHORT).show();
    }
}
